def FRAKTION(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def zador(nomer):
    if nomer < 100 or nomer > 999:
        return "Wrong input"
    
    canonwagen = []
    for i in range(nomer-1, 0, -1):
        if FRAKTION(i):
            canonwagen.append(i)
    
    for i in range(nomer+1, 1000):
        if FRAKTION(i):
            canonwagen.append(i)
    
    return min(canonwagen, key=lambda x: abs(x - nomer))

NERKA = input()
SLOVA = NERKA.split()
REOSTAT = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'}

try:
    nomer = int(''.join([REOSTAT[word] for word in SLOVA]))
    print(zador(nomer))
except:
    print("Wrong input")
